package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.Taxi;
import cn.anxingongyou.anxin.mapper.TaxiMapper;
import cn.anxingongyou.anxin.service.TaxiService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class TaxiServiceImpl implements TaxiService {

    private final TaxiMapper taxiMapper;
    @Autowired
    public TaxiServiceImpl(TaxiMapper taxiMapper) {
        this.taxiMapper = taxiMapper;
    }

    @Override
    public int insert(Taxi taxi) {
        return taxiMapper.insertSelective(taxi);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return taxiMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Taxi taxi) {
        return taxiMapper.updateByPrimaryKeySelective(taxi);
    }

    @Override
    public Taxi selectOne(Taxi taxi) {
        return taxiMapper.selectOne(taxi);
    }

    @Override
    public Taxi selectOneByPrimaryKey(Long id) {
        return taxiMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Taxi> page(int pageNum, int pageSize, Taxi taxi) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);
        List<Taxi> list = taxiMapper.select(taxi);
        PageInfo<Taxi> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<Taxi> selectByTime(int pageNum, int pageSize, Taxi taxi) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);

        Example example = new Example(Taxi.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("mode",taxi.getMode());
        criteria.andGreaterThan("beginDatestamp",new Date());
        List<Taxi> list = taxiMapper.selectByExample(example);
        PageInfo<Taxi> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
